home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 43
/
Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso
/
-serious-
/
wb
/
flynn
/
source
/
window.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-06-15
|
7KB
|
259 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <utility/tagitem.h>
#include <intuition/intuition.h>
#include <guigfx/guigfx.h>
#include <exec/memory.h>
#include <clib/macros.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/utility.h>
#include <proto/guigfx.h>
#include <proto/intuition.h>
#include <proto/guigfx.h>
#include "defs.h"
#include "global.h"
#include "window.h"
/*********************************************************************
----------------------------------------------------------------------
ClearWindow(win)
----------------------------------------------------------------------
*********************************************************************/
void ClearWindow(struct mvwindow *win)
{
UpdateWindowParameters(win);
SetABPenDrMd(win->window->RPort, win->backpen, win->backpen, JAM1);
RectFill(win->window->RPort,
win->innerleft + win->leftoffs,
win->innertop + win->topoffs,
win->innerleft+win->innerwidth-win->rightoffs-1,
win->innertop+win->innerheight-win->bottomoffs-1);
}
/*********************************************************************
----------------------------------------------------------------------
void UpdateWindowParameters(mvwindow)
get current window parameters
----------------------------------------------------------------------
*********************************************************************/
void UpdateWindowParameters(struct mvwindow *win)
{
win->winleft = win->window->LeftEdge;
win->wintop = win->window->TopEdge;
win->winwidth = win->window->Width;
win->winheight = win->window->Height;
win->innerleft = win->window->BorderLeft;
win->innertop = win->window->BorderTop;
win->innerwidth = win->winwidth - win->innerleft - win->window->BorderRight;
win->innerheight = win->winheight - win->innertop - win->window->BorderBottom;
}
/*********************************************************************
----------------------------------------------------------------------
DeleteMVWindow (mvwindow)
----------------------------------------------------------------------
*********************************************************************/
void DeleteMVWindow (struct mvwindow *win)
{
if (win)
{
if (win->window)
{
ReleasePen(win->screen->ViewPort.ColorMap, win->backpen);
CloseWindow(win->window);
}
Free(win);
}
}
/*********************************************************************
----------------------------------------------------------------------
mvwindow = CreateMVWindow (screen)
----------------------------------------------------------------------
*********************************************************************/
#define inserttag(x,t,d) {(x)->ti_Tag=(t);((x)++)->ti_Data=(ULONG)(d);}
struct mvwindow *CreateMVWindow (WORD x, WORD y, WORD width, WORD height)
{
struct mvwindow *win = NULL;
struct Screen *screen;
if (screen = LockPubScreen(NULL))
{
if (win = Malloclear(sizeof(struct mvwindow)))
{
BOOL success = FALSE;
struct TagItem *taglist;
win->backpen = -1;
win->screen = screen;
if(taglist = AllocateTagItems(20))
{
UWORD visibleWidth, visibleHeight, visibleMidX, visibleMidY;
// UWORD visibleLeft, visibleTop;
WORD winwidth, winheight, wintop, winleft;
struct TagItem *tp = taglist;
ULONG modeID;
visibleWidth = screen->Width;
visibleHeight = screen->Height;
if ((modeID = GetVPModeID(&screen->ViewPort)) != INVALID_ID)
{
DisplayInfoHandle dih;
if(dih = FindDisplayInfo(modeID))
{
struct DimensionInfo di;
if(GetDisplayInfoData(dih, (UBYTE*) &di, sizeof(di), DTAG_DIMS, modeID))
{
visibleWidth = di.TxtOScan.MaxX - di.TxtOScan.MinX;
visibleHeight = di.TxtOScan.MaxY - di.TxtOScan.MinY;
}
}
}
// visibleLeft = -screen->ViewPort.DxOffset;
// visibleTop = -screen->ViewPort.DyOffset;
visibleMidX = visibleWidth/2 - screen->ViewPort.DxOffset;
visibleMidY = visibleHeight/2 - screen->ViewPort.DyOffset;
// winwidth = MAX(visibleWidth * 3 / 7, DEFAULT_MINWIDTH);
// winheight = MAX(visibleHeight * 3 / 7, DEFAULT_MINHEIGHT);
winwidth = width;
winheight = height;
inserttag(tp, WA_Width, winwidth);
inserttag(tp, WA_Height, winheight);
winleft = (x >= 0) ? x : visibleMidX - winwidth/2;
wintop = (y >= 0) ? y : visibleMidY - winheight/2;
inserttag(tp, WA_Left, winleft);
inserttag(tp, WA_Top, wintop);
// win->otherwinpos[0] = visibleLeft;
// win->otherwinpos[1] = visibleTop;
// win->otherwinpos[2] = visibleWidth;
// win->otherwinpos[3] = visibleHeight;
// inserttag(tp, WA_Zoom, &win->otherwinpos);
inserttag(tp, WA_PubScreen, screen);
// inserttag(tp, WA_Title, DEFAULT_WINTITLE);
inserttag(tp, WA_NewLookMenus, TRUE);
inserttag(tp, WA_Flags,
WFLG_RMBTRAP |
WFLG_BORDERLESS |
WFLG_SMART_REFRESH);
inserttag(tp, WA_IDCMP,
IDCMP_NEWSIZE |
IDCMP_ACTIVEWINDOW |
IDCMP_INACTIVEWINDOW |
IDCMP_VANILLAKEY | IDCMP_RAWKEY |
IDCMP_MOUSEBUTTONS);
inserttag(tp, WA_MinWidth, DEFAULT_MINWIDTH);
inserttag(tp, WA_MinHeight, DEFAULT_MINHEIGHT);
inserttag(tp, WA_MaxWidth, DEFAULT_MAXWIDTH);
inserttag(tp, WA_MaxHeight, DEFAULT_MAXHEIGHT);
inserttag(tp, TAG_DONE, 0);
if(win->window = OpenWindowTagList(NULL, taglist))
{
win->idcmpSignal = 1L << win->window->UserPort->mp_SigBit;
win->backpen = ObtainBestPen(win->screen->ViewPort.ColorMap,
RED_RGB32(RGB_CLEARWINDOW),
GREEN_RGB32(RGB_CLEARWINDOW),
BLUE_RGB32(RGB_CLEARWINDOW),
OBP_Precision, PRECISION_ICON, TAG_DONE);
memset(&win->sizegadget, 0, sizeof(struct Gadget));
win->sizegadget.LeftEdge = win->window->Width-SIZESIZE;
win->sizegadget.TopEdge = win->window->Height-SIZESIZE;
win->sizegadget.Width = SIZESIZE;
win->sizegadget.Height = SIZESIZE;
win->sizegadget.Flags = GFLG_GADGHNONE;
win->sizegadget.Activation = 0;
win->sizegadget.GadgetType = GTYP_SIZING;
AddGadget(win->window, &win->sizegadget, ~0);
memset(&win->draggadget, 0, sizeof(struct Gadget));
win->draggadget.LeftEdge = 0;
win->draggadget.TopEdge = 0;
win->draggadget.Width = win->window->Width;
win->draggadget.Height = win->window->Height;
win->draggadget.Flags = GFLG_GADGHNONE;
win->draggadget.Activation = 0;
win->draggadget.GadgetType = GTYP_WDRAGGING;
AddGadget(win->window, &win->draggadget, ~0);
ClearWindow(win);
success = TRUE;
}
FreeTagItems(taglist);
}
if (!success)
{
DeleteMVWindow(win);
win = NULL;
}
}
UnlockPubScreen(NULL, screen);
}
return win;
}
#undef inserttag